//
// BuildingsManageListViewController.m
//  Utils
//
//  Created by enghou on 2018/4/28.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "BuildingsManageListViewController.h"
#import "BuildingsSearchViewController.h"
#import "BuildinglayoutViewController.h"
#import "BuildingLayoutItemModel.h"
#import "BuildingItemModel.h"
#import "BuildingDetailViewController.h"
@interface BuildingsManageListViewController ()

@end

@implementation BuildingsManageListViewController

-(void)searchAction{
    BuildingsSearchViewController *building = (BuildingsSearchViewController *)[VCLoader vcWithName:@"BuildingsSearchViewController"];
    building.theDelete = self;
    building.title = @"楼宇查询";
    [self push:building];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(generateLayout:) name:@"GenerateLayout" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(bindBuilding:) name:@"BindBuilding" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(beginRefresh) name:@"RefreshLst" object:nil];
}

-(void)generateLayout:(NSNotification *)not{
    BuildingItemModel *model = not.object;
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    layout.itemSize = CGSizeMake(50, 70);
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    layout.headerReferenceSize = CGSizeMake(self.view.width, 30);
    BuildinglayoutViewController *build = [[BuildinglayoutViewController alloc]initWithCollectionViewLayout:layout];
    build.title = @"布局管理";
    build.needLayout = model.needLayout;
    build.ids = model.ids;
    [self push:build];
}

-(void)bindBuilding:(NSNotification *)not{
    BuildingItemModel *model = not.object;
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    layout.itemSize = CGSizeMake(50, 70);
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    layout.headerReferenceSize = CGSizeMake(self.view.width, 30);
    BuildinglayoutViewController *build = [[BuildinglayoutViewController alloc]initWithCollectionViewLayout:layout];
    build.title = @"布局管理";
    build.needLayout = model.needLayout;
    build.ids = model.ids;
    [self push:build];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)addAction{
    BuildingDetailViewController *detail = [[BuildingDetailViewController alloc]init];
    detail.title = @"楼宇新增";
    [self push:detail];
}

#pragma mark - Table view data source
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    BuildingItemModel *model = self.source[indexPath.row];
    BuildingDetailViewController *detail = [[BuildingDetailViewController alloc]init];
    detail.title = @"楼宇详情";
    detail.ids = model.ids;
    [self push:detail];
}
/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
